<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#div1 {width:100px; height:100px; background:red; position:absolute;}
</style>
<script>
window.onload=function ()
{
	var oDiv=document.getElementById('div1');
	
	var disX=0;
	var disY=0;
	
	oDiv.onmousedown=function (ev)
	{
		var oEvent=ev||event;
		
		disX=oEvent.clientX-oDiv.offsetLeft;
		disY=oEvent.clientY-oDiv.offsetTop;
		
		if(oDiv.setCapture)
		{
			//IE
			oDiv.onmousemove=mouseMove;
			oDiv.onmouseup=mouseUp;
			
			oDiv.setCapture();
		}
		else
		{
			//Chrome、FF
			document.onmousemove=mouseMove;
			document.onmouseup=mouseUp;
		}
		
		function mouseMove(ev)
		{
			var oEvent=ev||event;
			var l=oEvent.clientX-disX;
			var t=oEvent.clientY-disY;
			
			oDiv.style.left=l+'px';
			oDiv.style.top=t+'px';
		}
		
		function mouseUp()
		{
			this.onmousemove=null;
			this.onmouseup=null;
			
			if(oDiv.releaseCapture)
			{
				oDiv.releaseCapture();
			}
		}
		
		return false;	//chrome、ff、IE9
	};
};
</script>
</head>

<body>
asdfasdfsdf<br>
dfasfasdfasd
<div id="div1">asdfasdfsdf<br>
dfasfasdfasd</div>
asdfasdfsdf<br>
dfasfasdfasd
</body>
</html>
